<?php

class Airlines extends CI_Controller {
	
	public $user_data=array();
	function __construct()
     {
	     parent::__construct();
	     
		//不登陆的不让访问
		if (!$this->session->userdata('uadmin_in')){
			
			redirect('admin/home');
			exit();
		}
		
		$this->user_data["uadmin_name"] = $this->session->userdata('uadmin_name');
		$this->user_data["uadmin_userid"] = $this->session->userdata('uadmin_userid');
		$this->user_data["uadmin_account"] = $this->session->userdata('uadmin_account');

     }
    //新增航班页面
    public function index()
    {
    		$data=array();
    		$data["title"]="flight_manage";
    		$this->load->view("admin/AirLines/flights/flight_manage",$data);
    }
    
    //新增航班
    public function addFlight()
    {
    		$data=array();
				$data["cmd"]="add";
				$data["title"]="add Flight";
				
				$data["FlightID"]		="";
				
    		$data["FlightCode"]		="";
    		
    		$data["FlightNumber"]		="";
    		$data["Status"]		="";
    		$data["FromPort"]		="";
    		$data["DestPort"]		="";
    		$data["FlightDate"]		="";
    		$data["Time1"]			="";
    		$data["Time2"]		="";
    		$data["StopTimes"]		="";
    		$data["StopPort"]		="";
    		
    		$data["Planecode"]			="";
    		$data["PlaneModel"]		="";
    		$data["TotalF"]		="";
    		$data["TotalC"]	="";
    		$data["TotalY"]	="";
    		$data["AvbF"]	="";
    		$data["AvbC"]	="";
    		$data["AvbY"]	="";
    		
    		$data["WebCss"]		="default";
    		
    		$this->load->view("admin/AirLines/flights/add_Flight",$data);
    }
    //修改航班
    public function editFlight($userid)
    {
    		$data=array();
    		
    		
    		$this->load->model("Flight_model");
    		$agentdata=$this->Agent_model->get_agent($userid);
    		
    		$data=$agentdata;
    		    		
    		$data["title"]="edit agent";
    		$data["cmd"]="edit";
    		
    		$data["txAgencyCode"]=$data["AgencyCode"];
    		
    		$this->load->view("admin/AirLines/edit_Flight",$data);
    }
    //保存航班
    public function saveFlight()
    {
     	$this->load->model("Airlines_model");
     	
     	if($_POST["cmd"]=="add")
     	{
     		$saveresult = $this->Airlines_model->add_Flight($_POST,$this->user_data);	
     	}
     	else
     	{
     		$saveresult = $this->Airlines_model->edit_Flight($_POST,$this->user_data);	
     	}
     	
   	 	echo '<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>';
    		if($saveresult)
    		{
    			//echo "Saved successfully";  
    			
    			$url=site_url("admin/Airlines/editFlight/".$saveresult["FlightID"]);
			echo "<SCRIPT>alert('Saved successfully');";
			echo 'window.parent.closewindow();';
			echo "</SCRIPT>";
			
			
    		}else
    		{
    			
    			$url="airorder/$bookresult[1]";
			echo "<SCRIPT LANGUAGE=\"JavaScript\">";
			echo "alert(\"save fail\");";
			echo "</SCRIPT>";  
    		}
    }
    //查询航班
    public function queryFlight()
    {
    	
    		$data=array();
    		$this->load->model("Agent_model");
    		
    		$result=$this->Agent_model->query_agent($_POST);
    		
    		$data["agentResult"]=$result;
    		$data["title"]="queryagent";
    		$this->load->view("admin/AirLines/queryFlight",$data);
    		
    		//echo '{"total":'.count($result).',"rows":'.json_encode($result).'}';
    }
    //新增舱位
	public function addClass()
	{
		 $data=array();
    		$data["Classcode"]		="Classcode_REPLACE_INDEX";
    		$data["ClassType1"]		="ClassType1_REPLACE_INDEX";
    		$data["ClassType2"]		="ClassType2_REPLACE_INDEX";
    		
    		$data["Rule"]			="Rule_REPLACE_INDEX";
    		$data["Changerule"]		="Changerule_REPLACE_INDEX";
    		$data["WebCss"]		="default";
    		
    		$this->load->view("admin/AirLines/flights/pop_select_class",$data);
    		  
		
		}
	

	//新增机型入口
	public function indexAirPlane()
	{
		$data=array();
    		$data["title"]="AirPlane_manage";
    		$this->load->view("admin/AirLines/AirPlane/AirPlane_manage",$data);
    	}	
    		
	//新增机型
	public function addAirPlane()
	{
		 $data=array();
		$data["cmd"]="add";
		$data["title"]="add AirPlane";
		
		$data["PlaneID"]		="";
    		$data["PlaneCode"]		="";
    		
    		$data["NickName"]		="";
    		$data["PlaneModel"]		="";
    		$data["TotalF"]		="";
    		$data["TotalC"]		="";
    		$data["TotalY"]		="";
    		
    		$data["WebCss"]		="default";
    		
    		$this->load->view("admin/AirLines/AirPlane/Edit_AirPlane",$data);
    		  
		
		}
	//修改账号
    public function editAirplane($PlaneID)
    {
    		$data=array();
    		
    		
    		$this->load->model("Airlines_model");
    		$planedata=$this->Airlines_model->get_Airplane($PlaneID);
    		
    		$data=$planedata;
    		    		
    		$data["title"]="edit Airplane";
    		$data["cmd"]="edit";
    		
     		
    		$this->load->view("admin/AirLines/Airplane/Edit_AirPlane",$data);
    }
	
 	//保存机型
    public function saveAirPlane()
    {
     	$this->load->model("Airlines_model");
     	
     	if($_POST["cmd"]=="add")
     	{
     		$saveresult = $this->Airlines_model->add_AirPlane($_POST,$this->user_data);	
     	}
     	else
     	{
     		$saveresult = $this->Airlines_model->edit_AirPlane($_POST,$this->user_data);	
     	}
     	
   	 	echo '<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>';
    		if($saveresult)
    		{
    			//echo "Saved successfully";  
    			
    			$url=site_url("admin/Airlines/editAirplane/".$saveresult["PlaneID"]);
			echo "<SCRIPT LANGUAGE=\"JavaScript\">";
			echo "alert(\"Saved successfully\");";
			echo "window.location='$url';";
			echo "</SCRIPT>";  
			
    		}else
    		{
    			
    			$url="";
			echo "<SCRIPT LANGUAGE=\"JavaScript\">";
			echo "alert(\"save fail\");";
			echo "</SCRIPT>";  
    		}
    }
    
    //查询机型
    public function queryAirPlane()
    {
    	
    		$data=array();
    		$this->load->model("Airlines_model");
    		
    		$result=$this->Airlines_model->query_Airplane($_POST);
    		
    		$data["airplaneResult"]=$result;
    		$data["title"]="queryAirplane";
    		$this->load->view("admin/AirLines/Airplane/queryAirplane",$data);
    		
    		//echo '{"total":'.count($result).',"rows":'.json_encode($result).'}';
    }
	
}


?>